package com.rainman.simpleredis.demo.mq_worker;

import com.rainman.simpleredis.core.SimpleRedis;
import com.rainman.simpleredis.core.simplemq.SimpleMqWorkerInterface;
import com.rainman.simpleredis.core.simplemq.WorkerReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * MQ消费者
 *
 */
@Component
public class Worker2 implements SimpleMqWorkerInterface {

    Random xx=new Random();


    @Override
    public WorkerReturn doWork(String targetType,String targetId, String msgValue) {
        System.out.println(System.currentTimeMillis()+"Worker2 doWork"+targetId+" "+msgValue);

        try {
            Thread.sleep(1111);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        int i = xx.nextInt(2);

        if(i==0){
            //throw new RuntimeException("模拟异常"+targetType+" "+targetId+" "+msgValue);
        }

        return new WorkerReturn(WorkerReturn.StateSuc,null);
    }

    @Override
    public Boolean matchTargetType(String targetType) {
        return targetType.equals("200");
    }
}
